#include <stdio.h> 
#include <stdlib.h>
#include <unistd.h>    // for pause()
#include <signal.h>    // for signal()
#include <sys/time.h>

static int count = 0;

void set_timer()
{
    struct itimerval itv;

    // timer start after 3 seconds later
    itv.it_value.tv_sec = 3;
    itv.it_value.tv_usec = 0;

    // after timer start, how long timer will to run each time 
    itv.it_interval.tv_sec = 1;
    itv.it_interval.tv_usec = 0;

    setitimer(ITIMER_REAL, &itv, NULL);
}

void signalHandler(int signo)
{
    if(signo == SIGALRM)
    {
        count++;
        printf("%d\n", count);
    }
}

int main(int argc, char *argv[])
{
    signal(SIGALRM, signalHandler);
    set_timer();
    while(count < 10);

    return 0;
}
